// Copyright (c) 2005-2008, Simon Howard

// Permission to use, copy, modify, and/or distribute this software
// for any purpose with or without fee is hereby granted, provided
// that the above copyright notice and this permission notice appear
// in all copies.

// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
// NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

/// Comparison functions for generic (void) pointers.

/// To find the difference between two pointers, use `pointer_compare`.

/// To find if two pointers are equal, use `pointer_equal`.

use std::cmp::Ordering;

/// Compare two pointers to determine if they are equal.
///
/// # Arguments
///
/// * `location1` - The first pointer.
/// * `location2` - The second pointer.
///
/// # Returns
///
/// Non-zero if the pointers are equal, zero if they are not equal.
pub fn pointer_equal(location1: *const (), location2: *const ()) -> bool {
    location1 == location2
}

/// Compare two pointers.
///
/// # Arguments
///
/// * `location1` - The first pointer.
/// * `location2` - The second pointer.
///
/// # Returns
///
/// A negative value if the first pointer is in a lower memory address than the second,
/// a positive value if the first pointer is in a higher memory address than the second,
/// zero if they point to the same location.
pub fn pointer_compare(location1: *const (), location2: *const ()) -> Ordering {
    if location1 < location2 {
        Ordering::Less
    } else if location1 > location2 {
        Ordering::Greater
    } else {
        Ordering::Equal
    }
}
